﻿using ConfigMgmtEx;
using System.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ConfigMgmtExTest
{
    
    
    /// <summary>
    ///This is a test class for ConfigHashTest and is intended
    ///to contain all ConfigHashTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ConfigHashTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ConfigHash Constructor
        ///</summary>
        [TestMethod()]
        public void ConfigHashConstructorTest()
        {
            ConfigHash target = new ConfigHash();
            Assert.IsNotNull(target);
        }

        [TestMethod]
        public void ConfigHashTest1()
        {
            ConfigHash h = new ConfigHash();
            h.Add("Hallo", new ConfigEntry("Welt"));
            Assert.AreEqual(h["Hallo"].ConfigValue, "Welt");
        }


        [TestMethod]
        public void ConfigHashTest3()
        {
            ConfigHash h = new ConfigHash();
            h.Add("Hallo", "Welt");
            Assert.AreEqual(h["Hallo"].ConfigValue, "Welt");
        }


        /// <summary>
        ///A test for CreateFromXml
        ///</summary>
        [TestMethod()]
        public void CreateFromXmlTest()
        {
            SaveAsXmlTest();
            ConfigHash h = ConfigHash.CreateFromXml("TestHashPersisted.xml");
            Assert.AreEqual(h["Setting1"].ConfigValue, "World");
            Assert.AreEqual(h["Setting2"].ConfigValue, "Welt");
        }

        /// <summary>
        ///A test for SaveAsXml
        ///</summary>
        [TestMethod()]
        public void SaveAsXmlTest()
        {
            ConfigHash h = new ConfigHash();
            h.Add("Setting1", "World");
            h.Add("Setting2", new ConfigEntry("Welt"));
            h.SaveAsXml("TestHashPersisted.xml");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("TestHashPersisted.xml");
            Assert.AreEqual(xmlDoc.DocumentElement.Name, "ConfigHash");
        }
    }
}
